
#ifndef COMMON_FIBER_POOL_H_
#define COMMON_FIBER_POOL_H_

#include "fiber-env/fiber-env.h"
#include "interface/logger.h"
#include "./module-logger.h"
#include <memory>
#include <string>
#include <vector>

namespace fasmio { namespace common {

class FiberPool
{
public:
    explicit FiberPool(ILogger* logger, const char* fiber_name);
    virtual ~FiberPool();

public:
    bool Start(unsigned int fiber_count);
    void Stop();

protected:
    virtual void Worker() = 0;

protected:
    ILogger* const logger_;
    ModuleLogger mlogger_;
    std::unique_ptr<fiber_env::IEvent> const quit_event_;

private:
    static int Worker(void* arg);

private:
    std::string fiber_pool_name_;

    typedef std::vector<fiber_env::Fiber*> fibers_t;
    fibers_t fibers_;
};

}}  // namespace fasmio::common

#endif  // COMMON_FIBER_POOL_H_

